// decProgressBar.cpp: implementation of the decProgressBar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "decProgressBar.h"
#include "DlgProgressBar.h"
#include "PrimaryResourceHandleSet.h"


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
static DlgProgressBar m_dlg;
decProgressBar::decProgressBar()
{
}

decProgressBar::~decProgressBar()
{
	m_dlg.DestroyWindow();
}

void decProgressBar::ShowWindow(const TCHAR *title)
{
	PrimaryResourceHandleSet hh;
	m_dlg.Create(DlgProgressBar::IDD,AfxGetMainWnd());
	m_dlg.SetWindowText(title);
	m_dlg.CenterWindow();
	m_dlg.ShowWindow(SW_SHOW);
}

void decProgressBar::SetProgressRange(UINT imin, UINT imax)
{
	ASSERT(IsWindow(m_dlg.GetSafeHwnd()));
	m_dlg.m_progress.SetRange(imin,imax);
}
static BOOL deal_msg()
{
	BOOL rt=FALSE;
	MSG msg;
	CWinApp*pApp=AfxGetApp();
 	while(::PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
 	{
		if(msg.message==WM_KEYDOWN && msg.wParam==VK_ESCAPE)
		{
			rt=TRUE;
		}
		if ((msg.message < WM_KEYFIRST || msg.message > WM_KEYLAST) &&
			(msg.message < WM_MOUSEFIRST || msg.message > WM_MOUSELAST) &&
			(msg.message < WM_NCMOUSEMOVE || msg.message > WM_NCMBUTTONDBLCLK))
		{
 			pApp->PumpMessage();
		}
 	}
	return rt;
}
BOOL decProgressBar::SetProgressPos(UINT pos)
{
	ASSERT(IsWindow(m_dlg.GetSafeHwnd()));
	m_dlg.m_progress.SetPos(pos);
	return deal_msg();
}

BOOL decProgressBar::StepItProgress()
{
	ASSERT(IsWindow(m_dlg.GetSafeHwnd()));
	m_dlg.m_progress.StepIt();
	return deal_msg();
}

void decProgressBar::SetNote(CString cs)
{
	if (IsWindow(m_dlg.GetSafeHwnd()))
	{
		m_dlg.m_csEdit_SourceText = cs;
		//m_dlg.m_ctrlEdit_SourceText.SetWindowText(cs);

		//m_dlg.m_ctrlEdit_SourceText.SetSel(-1, -1);
		//m_dlg.m_ctrlEdit_SourceText.ReplaceSel(cs + "\r\n\r\n");
		m_dlg.UpdateData(FALSE);

	}
}
